package com.java110.mall.goods.cmd.productCategory;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.product.ProductCategoryDto;
import com.java110.mall.goods.bmo.productCategory.IGetProductCategoryBMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "productCategory.queryCategoryProducts")
public class QueryCategoryProductsCmd extends Cmd {
    @Autowired
    private IGetProductCategoryBMO getProductCategoryBMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        super.validatePageInfo(reqJson);
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {

        ProductCategoryDto productCategoryDto = BeanConvertUtil.covertBean(reqJson,ProductCategoryDto.class);

        if (StringUtil.isEmpty(productCategoryDto.getState())){//默认上架商品
            productCategoryDto.setState("2002");
        }

        ResponseEntity<String> responseEntity = getProductCategoryBMOImpl.queryCategoryProducts(productCategoryDto);
        context.setResponseEntity(responseEntity);
    }
}
